package Test_1015;

/**
 * Created with Intellij IDEA
 * Description:
 * User: 星辰
 * Dare: 2024-10-15
 * Time: 14:26
 */
public class Test_1015 {
    public static void main13(String[] args) {
        //同时抛出多个异常
        try{
            System.out.println("111");
            int[] a={1,2,3};
            System.out.println(a[4]);
            System.out.println("123");
            System.out.println(10/0);
        }catch(Exception e){
            System.out.println("捕获到异常");
        }
        System.out.println("1111");
    }
    public static void main14(String[] args) {
     /*   try{
            System.out.println("111");
            int[] a={1,2,3};
            System.out.println(a[4]);
            System.out.println("123");
            System.out.println(10/0);
        }*/
        System.out.println("1111");
    }
    public static void main12(String[] args) {
        try{
            System.out.println(10/0);
        }catch(ArithmeticException e){
            throw new ArithmeticException();
        }
        System.out.println("111");
    }
    public static void main11(String[] args) {
        try{
            System.out.println(10/0);
        }catch(Throwable e){
            System.out.println("捕获");
        }
    }
    public static void main10(String[] args) {
        try{
            System.out.println(10/0);
        }catch(ArithmeticException e){
            System.out.println("捕获错误");
        }catch(Throwable throwable){
            System.out.println("捕获运行时异常");
        }
    }
    public static void main9(String[] args) {
        try{
            System.out.println(10/0);
        }catch(Exception e){
            System.out.println("捕获错误");
        }
    }
    public static void main8(String[] args) {
        try{
            System.out.println(10/0);
        }catch(Error error){
            System.out.println("捕获错误");
        }catch(Throwable throwable){
            System.out.println("捕获运行时异常");
        }
    }
    public static void main7(String[] args) {
        try{
            System.out.println(10/0);
        }catch(Throwable throwable){
            System.out.println("捕获运行时异常");
        }
    }
    public static void main6(String[] args) {
        try{
            System.out.println(10/0);
        }catch(RuntimeException exception){
            System.out.println("捕获运行时异常");
        }
        try{
            System.out.println(10/0);
        }catch(Exception exception){
            System.out.println("捕获异常");
        }
    }
    public static void main5(String[] args) {
        try{
        System.out.println(10/0);
        }catch(ArithmeticException e){
            //捕获异常
            System.out.println("捕获算术异常");
        }
        //其后面的代码可以执行
        System.out.println("1111");
    }
    public static void main4(String[] args) {
        try{
            System.out.println(10/0);
        }catch(RuntimeException e){
            System.out.println("捕获运行时异常");
        }
    }
    //如果第一个catch是父类异常，那么第二个catch不能再捕获异常
    public static void main3(String[] args) {
        try{
            System.out.println(10/0);
        }catch(RuntimeException e){
            System.out.println("捕获运行时异常");
            throw new RuntimeException();
        }/*catch(ArithmeticException e){
            System.out.println("捕获到算术异常");
            throw new ArithmeticException();
        }*/
    }
    //可以单独捕捉算术异常，其余运行时异常有父类捕获
    public static void main2(String[] args) {
        try{
            System.out.println(10/0);
        }catch(ArithmeticException e){
            System.out.println("捕获到算术异常");
        }catch(RuntimeException e){
            System.out.println("捕获到运行时异常");
        }
    }
    public static void main1(String[] args) {
        //同时抛出多个异常
        try{
            System.out.println("111");
            int[] a={1,2,3};
            System.out.println(a[4]);
            System.out.println("123");
            System.out.println(10/0);
        }catch(ArithmeticException e){
            System.out.println("捕获到算术异常");
        }catch(ArrayIndexOutOfBoundsException e){
            System.out.println("捕获到数组越界异常");
        }
        System.out.println("1111");
    }
}
